package com.example.owner.lettery1.other;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ListView;

import com.example.owner.lettery1.R;


/**
 * Created by Administrator on 2016/10/29.
 */
public class TableView extends FrameLayout {
    private LinearLayout mParentLayout;
    private FrameLayout mHeaderLayout;
    private View mHeaderDividerView;
    private ListView mTableView;
    private String[] mTitles;
    private TextTableAdapter mAdapter;
    private Context mContext;

    public TableView(Context context) {
        super(context);
        mContext = context;
        initView();
    }

    public TableView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        initView();
    }

    private void initView() {
        mParentLayout = (LinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.table_view, this, false);
        mHeaderLayout = (FrameLayout) mParentLayout.getChildAt(0);
        mHeaderDividerView = mParentLayout.getChildAt(1);
        mTableView =  mParentLayout.findViewById(R.id.swipe_target);
        this.addView(mParentLayout);
    }




    public void setAdapter(TextTableAdapter<String> adapter) {
        mTableView.setAdapter(mAdapter = adapter);
    }


    public void setTitles(ItemCreator itemCreator, String... titles) {
        mHeaderLayout.setVisibility(VISIBLE);
        mHeaderDividerView.setVisibility(VISIBLE);
        mTitles = titles;
        TextTableViewHolder holder = itemCreator.createItem(mTitles);
        holder.setTextSize(0,15);
        holder.setTextSize(1,15);
        holder.setTextSize(2,15);
        holder.setTextColor(0, Color.rgb(51,51,51));
        holder.setTextColor(1, Color.rgb(51,51,51));
        holder.setTextColor(2, Color.rgb(51,51,51));
        mHeaderLayout.addView(holder.getRowLayout());
    }


    public String[] getHeaderTitles() {
        return mTitles;
    }


    public void setHeaderHeight(int height) {
        ViewGroup.LayoutParams params = mHeaderLayout.getLayoutParams();
        params.height = height;
        mHeaderLayout.setLayoutParams(params);
    }

    public void setHorizontalDivider(Drawable divider) {
        mTableView.setDivider(divider);
    }




}
